<?php

/**
 * Created on 7 mai 2011
 *  * @author Samy Deghou(deghou@polytech.unice.fr ; deghou@embl.de)
 * 		   Stephan Beisken (beisken@ebi.ac.uk)
 * 		   Luis Felipe De Figueiredo (ldpf@ebi.ac.uk)
 * To change the template for this generated file go to
 * Window - Preferences - PHPeclipse - PHP - Code Templates
 */
class RawFile implements iCRUD {
    /*
     * Attributes
     */

    private $_rawFileID;
    private $_file;
    private $_format;

    /*
     * Constructor
     */

    public function RawFile($file, $format, $rawFileID=-1) {
        $this->_file = $file;
        $this->_format = $format;
        $this->_rawFileID = $rawFileID;
    }

    /*
     * Accessors
     */

    public function getRawFileID() {
        return $this->_rawFilelID;
    }

    public function getFile() {
        return $this->_file;
    }

    public function getFormat() {
        return $this->_format;
    }

    /*
     * Modifiers
     */

    public function setRawFileID($param) {
        $this->_rawFilelID = $param;
    }

    public function setFile($param) {
        $this->_file = $param;
    }

    public function setFormat($param) {
        $this->_forma = $paramt;
    }

    /*
     * CRUD
     */

    /**
     * Put an object in the database
     */
    public function create() {
        Database::connect();
        if ($this->_rawFileID != -1)
            die("Unable to create, still existing !");
        else {
            $query = "INSERT INTO `RAW_FILE` values (NULL,'" .
                    $this->_file . "','" .
                    $this->_format . "')";
            mysql_query($query) or die(mysql_error());
            $this->_idSujet = mysql_insert_id();
        }
        Database::disconnect();
    }

    /**
     * Read an object from the database
     */
    public static function read($key) {
        Database::connect();
        $query = "SELECT * FROM RAW_FILE WHERE raw_file_id = '" . $key . "'";
        $ans = mysql_fetch_assoc(mysql_query($query));
        extract($ans);
        Database::disconnect();
        return new RawFile($file, $format, $raw_file_id);
        Database::disconnect();
    }

    /**
     * Update an object from the database
     */
    public function update() {
        Database::connect();
        $query = "UPDATE `RAW_FILE` SET file='" .
                $this->_file . "', format='" .
                $this->_format . "' WHERE raw_file_id='" .
                $this->_rawFileID . "'";
        mysql_query($query) or die(mysql_error());
        Database::disconnect();
    }

    /**
     * Delete an object from the database
     */
    public function delete() {
        Database::connect();
        $query = "DELETE FROM `RAW_FILE` WHERE raw_file_id='" .
                $this->_rawFileID . "'";
        mysql_query($query) or die(mysql_error());
        Database::disconnect();
    }

}
?>
